using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Data;
namespace Test {
	class ImgBHistogram {
		static void MainC() {
			DAL dal=new DAL("pon-wpsq16-db.Directory".Split('.'));
			string sql=@"SELECT datediff(hour,b.CreatedDate,pck.EventDate)[hour],count(*)[items]
from DirBatch b(nolock)join DirPickWalk w(nolock)on b.RecordID=w.BatchID
join DirPickWalkDetail wd(NOLOCK)on w.RecordID = wd.PickWalkId
join dirParcelDetail pd(nolock)on pd.CustomerNumber=wd.CustomerNumber and pd.InvoiceNumber=wd.InvoiceNumber
join dirParcel p(nolock)on p.RecordID=pd.ParcelRecordId
left join dirNoStock ns(nolock) on ns.CustomerNumber=wd.CustomerNumber and ns.InvoiceNumber=wd.InvoiceNumber
 join (select DeliveryNoteNumber,max(EventDate)EventDate from dirParcelLog(nolock)where EventType=2 group by DeliveryNoteNumber
)pck on pck.DeliveryNoteNumber=pd.DeliveryNoteNumber --where b.RecordId=98900
group by datediff(hour,b.CreatedDate,pck.EventDate)
order by 1";
			int height=450;
			DataTable tab=dal.Query(sql);
			int sum=(int)tab.Compute("max(items)",null);
			int maxX=(int)tab.Compute("max(hour)",null);
			int left=0;
			Bitmap bmp=new Bitmap((maxX+2)*5,height);
			Graphics g=Graphics.FromImage(bmp);
			g.Clear(Color.White);
			foreach(DataRow row in tab.Rows)
			{
				float valY=(float)(int)(row["items"])/sum;

				valY=(float)Math.Pow(valY,0.4);

				int valX=(int)row["hour"];
				g.FillRectangle(Brushes.Red,valX*5,height*(1-valY),5,height*valY);
				g.DrawRectangle(Pens.Black,valX*5,height*(1-valY),5,height*valY);
				left+=5;
			}
			bmp.Save("C:\\test.png",System.Drawing.Imaging.ImageFormat.Png);
			System.Diagnostics.Process.Start("C:\\test.png");
		}
	}
}
